#include "app_debug_printf.h"

#include <stdio.h>
#include <stdarg.h>
#include <string.h>

#define DEBUG_PRINTF_BUF_SIZE 1024
static char debug_printf_buf[DEBUG_PRINTF_BUF_SIZE];

uint8_t debug_printf(const char *fmt, ...)
{
	memset(debug_printf_buf, 0, sizeof(debug_printf_buf));

	va_list arg;
	va_start(arg, fmt);
	vsnprintf(debug_printf_buf, sizeof(debug_printf_buf), fmt, arg);
	va_end(arg);

	if (HAL_OK != HAL_UART_Transmit_DMA(&DEBUG_PRINTF_UART, (uint8_t *)debug_printf_buf,
										strlen(debug_printf_buf)))
	{
		return 0;
	}

	while (!__HAL_UART_GET_FLAG(&DEBUG_PRINTF_UART, UART_FLAG_TC))
	{
	}

	return 1;
}